//
//  eBook Bundler.m
//  Capstone Project
//
//  Created by Brian Gilreath on 10/27/10.
//  Copyright 2010 GilreathCapstone. All rights reserved.
//

#import "eBook Bundler.h"
#import "OH_FeBookIndexer.h"
#import "OHbook.h"
#import "ZipArchive.h"

@implementation eBook_Bundler

@synthesize OHBookList, OHBookmarkList, OHHighlightList, OHNoteList;

-(eBook_Bundler*)init{
	if(self = [super init]){
		OH_FeBookIndexer *hello = [[OH_FeBookIndexer alloc] init];
		[hello release];
	}
	return self;
}

OHbook *EBCurrentBookOpened;

// The only thing this method does is loading the webview manager with the appropriate book
// html file, advanced implementations involve adding various functions, such as overlays
// and note taker areas, highlighting, etc.
-(int)OHopenBook:(OHbook *)book{
	EBCurrentBookOpened = book;
	// todo unload book
	// todo figure out associated objects
	// todo load first page into view, giving it an index to reference from
	return 0;
}


// In order to safely open another book, you must call the close book method to deallocate 
// the memory used for the open book
-(int)OHcloseBook{
	return 0;
}

-(int)OHcreateNote:(OHnote *)newNote{
	if (![OHNoteList containsObject:newNote]) {
		[OHNoteList addObject:newNote];
		return itemCreatedSuccessfully;
	}
	return itemNotCreated;
}

-(int)OHcreateHighlight:(OHhighlight *)newHighlight{
	if (![OHHighlightList containsObject:newHighlight]) {
		[OHHighlightList addObject:newHighlight];
		return itemCreatedSuccessfully;
	}
	return itemNotCreated;
}

-(int)OHcreateBookmark:(OHbookmark *)newBookmark{
	if (![OHBookmarkList containsObject:newBookmark]) {
		[OHBookmarkList addObject:newBookmark];
		return itemCreatedSuccessfully;
	}
	return itemNotCreated;
}

-(int)OHeditNote:(OHnote *)newNote:(OHnote *)oldNote{
	if (newNote == nil) {
		return itemNotEdited;
	}
	int index = [OHNoteList indexOfObject:oldNote];
	if ( index != NSNotFound) {
		[OHNoteList replaceObjectAtIndex:index
							  withObject:newNote];
		return itemEditedSuccessfully;
	}
	return itemDNE;
}

-(int)OHeditHighlight:(OHhighlight *)newHighlight:(OHhighlight *)oldHighlight{
	if (newHighlight == nil) {
		return itemNotEdited;
	}
	int index = [OHHighlightList indexOfObject:oldHighlight];
	if ( index != NSNotFound) {
		[OHHighlightList replaceObjectAtIndex:index
								   withObject:newHighlight];
		return itemEditedSuccessfully;
	}
	return itemDNE;
}

-(int)OHeditBookmark:(OHbookmark *)newBookmark:(OHbookmark *)oldBookmark{
	if (newBookmark == nil) {
		return itemNotEdited;
	}
	int index = [OHBookmarkList indexOfObject:oldBookmark];
	if ( index != NSNotFound) {
		[OHBookmarkList replaceObjectAtIndex:index
								  withObject:newBookmark];
		return itemEditedSuccessfully;
	}
	return itemDNE;
}

-(int)OHdeleteNote:(OHnote *)noteToDelete{
	int index = [OHNoteList indexOfObject:noteToDelete];
	if ( index != NSNotFound) {
		[OHNoteList removeObjectAtIndex:index];
		return itemRemoved;
	}
	return itemDNE;
}

-(int)OHdeleteHighlight:(OHhighlight *)highlightToDelete{
	int index = [OHHighlightList indexOfObject:highlightToDelete];
	if ( index != NSNotFound) {
		[OHNoteList removeObjectAtIndex:index];
		return itemRemoved;
	}
	return itemDNE;
}

-(int)OHdeleteBookmark:(OHbookmark *)bookmarkToDelete{
	int index = [OHBookmarkList indexOfObject:bookmarkToDelete];
	if ( index != NSNotFound) {
		[OHNoteList removeObjectAtIndex:index];
		return itemRemoved;
	}
	return itemDNE;
}

@end
